import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/attendance/attSchedule/list',
  save='/attendance/attSchedule/add',
  edit='/attendance/attSchedule/edit',
  deleteOne = '/attendance/attSchedule/delete',
  deleteBatch = '/attendance/attSchedule/deleteBatch',
  importExcel = '/attendance/attSchedule/importExcel',
  exportXls = '/attendance/attSchedule/exportXls',
  autoSchedule = '/attendance/attSchedule/autoSchedule',
  personSchedulelist = '/attendance/attSchedule/personSchedulelist',
  attScheduleSwap = '/attendance/attSchedule/swap',
  GroupList = '/baseinfo/ssPersonGroup/list',
  scheduleTree = '/attendance/attSchedule/scheduleTree',
  attScheduleSubmit = '/attendance/attSchedule/submit',
  grous = '/baseinfo/ssPersonGroup/list',
  timePeriods = '/attendance/attSchedule/getTimePeriodsByGroupId',
  attTimePeriodList = '/attendance/attTimePeriod/list',
  changeTimePeriod = '/attendance/attSchedule/changeTimePeriod',
  
  
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

export const attTimePeriodList = (params) =>
  defHttp.get({url: Api.attTimePeriodList, params});

export const GroupList = (params) =>
  defHttp.get({url: Api.GroupList, params});

export const personSchedulelist = (params) =>
  defHttp.post({url: Api.personSchedulelist, params})

export const scheduleTree = (params) =>
  defHttp.get({url: Api.scheduleTree, params});

export const attScheduleSwap = (params) => {
  return defHttp.get({url:  Api.attScheduleSwap, params});
}
export const getAllGroups = (params) => {
  return defHttp.get({url:  Api.grous, params});
}
export const getTimePeriods = (params) => {
  return defHttp.get({url:  Api.timePeriods, params});
}
  

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const autoSchedule = (params) => {
  let url =  Api.autoSchedule ;
  return defHttp.post({url: url, params});
}

export const attScheduleSubmit = (params) => {
  let url =  Api.attScheduleSubmit ;
  return defHttp.post({url: url, params});
}


export const changeTimePeriod = (params) => {
  let url =  Api.changeTimePeriod ;
  return defHttp.post({url: url, params});
}

